<?php

class Zhishidi_Express_Block_Adminhtml_Rate_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {

    protected function _prepareForm() {
        $form = new Varien_Data_Form();
        $this->setForm($form);
        $fieldset = $form->addFieldset('expressRateFieldset', array('legend' => Mage::helper('zhishidi_express')->__("Express Rate information")));


        $zoneCollection = Mage::getModel('zhishidi_express/zone')->getCollection()->joinZoneType()->joinZoneGroup()->addFieldToFilter('type_handle' ,'table_rate');
        $zoneArray = array();
        foreach ($zoneCollection as $zone) {
            $groupName = $zone->getGroupName();
            if (empty($groupName))
                $groupName = 'N/A';
            $zoneArray[] = array(
                'value' => $zone->getId(),
                'label' => $zone->getZoneName() . ' - ' . 'Type:' . $zone->getTypeName() . ' - ' . 'Group:' . $groupName,
            );
        }
        $fieldset->addField('rate_zone', 'select', array(
            'name' => 'rate_zone',
            'label' => Mage::helper('zhishidi_express')->__('Zone'),
            'title' => Mage::helper('zhishidi_express')->__('Zone'),
            'required' => true,
            'style' => 'width:500px;',
            'values' => $zoneArray,
        ));

        $fieldset->addField('rate_from', 'text', array(
            'name' => 'rate_from',
            'label' => Mage::helper('zhishidi_express')->__('Weight From (g)'),
            'title' => Mage::helper('zhishidi_express')->__('Weight From (g)'),
            'class' => 'required-entry',
             'style' => 'width:100px;',
            'required' => true,
        ));

        $fieldset->addField('rate_to', 'text', array(
            'name' => 'rate_to',
            'label' => Mage::helper('zhishidi_express')->__('Weight To (g)'),
            'title' => Mage::helper('zhishidi_express')->__('Weight To (g)'),
            'style' => 'width:100px;',
             'class' => 'required-entry',
            'required' => true,
        ));


        $fieldset->addField('rate_price', 'text', array(
            'name' => 'rate_price',
            'label' => Mage::helper('zhishidi_express')->__('Rate Price'),
            'title' => Mage::helper('zhishidi_express')->__('Rate Price'),
            'style' => 'width:100px;',
            'required' => true,
        ));
   

        if (Mage::getSingleton('adminhtml/session')->getExpressRateData()) {
            $form->setValues(Mage::getSingleton('adminhtml/session')->getExpressRateData());
            Mage::getSingleton('adminhtml/session')->setExpressRateData(null);
        } elseif (Mage::registry('express_rate_data')) {
            $form->setValues(Mage::registry('express_rate_data')->getData());
        }
        return parent::_prepareForm();
    }

}